package logback;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-4
 * Time: 下午9:34
 * To change this template use File | Settings | File Templates.
 */
public class LoggerUtil {
    /**
     * 运行日志名
     */
    public static final String RUN_LOGGER_NAME = "runLogger";

    /**
     * 接口日志名
     */
    public static final String INTERFACE_LOGGER_NAME = "interfaceLogger";
    public static final String INTERFACE_IN = "in";
    public static final String INTERFACE_OUT = "out";

    /**
     * 登录日志名
     */
    public static final String LOGIN_LOGGER_NAME = "loginLogger";

    /**
     * 操作日志名
     */
    public static final String OPERATE_LOGGER_NAME = "operateLogger";

    /**
     * trace运行日志
     * @param msg
     * @param argArray
     */
    public static void traceRun(String msg, Object... argArray) {
        Logger logger = LoggerFactory.getLogger(RUN_LOGGER_NAME);

        logger.trace(msg, argArray);
    };

    /**
     * debug运行日志
     * @param msg
     * @param argArray
     */
    public static void debugRun(String msg, Object... argArray) {
        Logger logger = LoggerFactory.getLogger(RUN_LOGGER_NAME);

        logger.debug(msg, argArray);
    };

    /**
     * info运行日志
     * @param msg
     * @param argArray
     */
    public static void infoRun(String msg, Object... argArray) {
        Logger logger = LoggerFactory.getLogger(RUN_LOGGER_NAME);

        logger.info(msg, argArray);
    };

    /**
     * error运行日志
     * @param msg
     * @param argArray
     */
    public static void errorRun(String msg, Object... argArray) {
        Logger logger = LoggerFactory.getLogger(RUN_LOGGER_NAME);

        logger.error(msg, argArray);
    };

    /**
     * error运行日志
     * @param msg
     */
    public static void errorRun(String msg, Throwable t) {
        Logger logger = LoggerFactory.getLogger(RUN_LOGGER_NAME);

        logger.error(msg, t);
    };


    /**
     * info接口日志
     */
    public static void infoInterfaceIn(String statusMsg, String componentName, String InterfaceName, Object... parameters) {
        Logger logger = LoggerFactory.getLogger(INTERFACE_LOGGER_NAME);

        logger.info("{} {} {} parameters:{} -- {}", new Object[]{INTERFACE_IN, componentName, InterfaceName, StringUtils.join(parameters, ","), statusMsg});
    };

    /**
     * info接口日志
     */
    public static void infoInterfaceOut(String statusMsg, String componentName, String InterfaceName, Object... parameters) {
        Logger logger = LoggerFactory.getLogger(INTERFACE_LOGGER_NAME);

        logger.info("{} {} {} parameters:{} -- {}", new Object[]{INTERFACE_OUT, componentName, InterfaceName, StringUtils.join(parameters, ","), statusMsg});
    };

    /**
     * error接口日志
     * @param msg
     */
    public static void errorInterface(String msg, Throwable t, Object... parameters) {
        Logger logger = LoggerFactory.getLogger(INTERFACE_LOGGER_NAME);

        msg += " parameters:" + StringUtils.join(parameters, ",");
        logger.error(msg, t);
    };

    /**
     * info登录日志
     */
    public static void infoLogin( String statusMsg, String userName) {
        Logger logger = LoggerFactory.getLogger(LOGIN_LOGGER_NAME);

        logger.info("userName:{} -- {}", userName, statusMsg);
    };

    /**
     * error登录日志
     * @param msg
     */
    public static void errorLogin(String msg, Throwable t) {
        Logger logger = LoggerFactory.getLogger(LOGIN_LOGGER_NAME);

        logger.error(msg, t);
    };

    /**
     * info操作日志
     */
    public static void infoOperate(String statusMsg, String userName, String operateName, Object... parameters) {
        Logger logger = LoggerFactory.getLogger(OPERATE_LOGGER_NAME);

        logger.info("userName:{} {} parameters:{}  -- {}", new Object[]{userName, operateName, StringUtils.join(parameters, ","), statusMsg});
    };

    /**
     * error操作日志
     * @param msg
     */
    public static void errorOperate(String msg, Throwable t) {
        Logger logger = LoggerFactory.getLogger(OPERATE_LOGGER_NAME);

        logger.error(msg, t);
    };
}
